//
//  HLNavgationController.swift
//  HLSwiftWork
//
//  Created by hulinhu on 2018/6/8.
//  Copyright © 2018年 hulinhu. All rights reserved.
//

import UIKit

class HLNavgationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
     navigationBar.setBackgroundImage(UIImage(named:"navigationbarBackgroundWhite"), for: .default)
        
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count > 0 {
            let button = UIButton(type: .custom)
            button.setTitle("返回", for: .normal)
            button.setImage(UIImage(named: "navigationButtonReturn"), for: .normal)
            button.setImage(UIImage(named: "navigationButtonReturnClick"), for: .highlighted)
            button.addTarget(self, action: #selector(back), for: .touchUpInside)
            button.setTitleColor(.darkGray, for: .normal)
            button.setTitleColor(.red, for: .highlighted)
            button.sizeToFit()
            button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0)
            button.contentHorizontalAlignment = .left
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: button)
            viewController.hidesBottomBarWhenPushed = true
         }
        
           super.pushViewController(viewController, animated: animated)
      }
    
      override var preferredStatusBarStyle: UIStatusBarStyle {
                return .default
       }


}


// MARK: - 点击事件
extension HLNavgationController {
    @objc func back(){
        popViewController(animated: true)
    }
}
